home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / librpc-xml-perl / examples / linux.proc.cpuinfo.xpl < prev    next >
Encoding:
Extensible Markup Language  |  2008-11-04  |  1.6 KB  |  61 lines

  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE proceduredef SYSTEM "rpc-method.dtd">
  3. <!--
  4.     Generated automatically by make_method v1.12, Wed Nov  5 03:59:32 2008
  5.  
  6.     Any changes made here will be lost.
  7. -->
  8. <proceduredef>
  9. <name>linux.proc.cpuinfo</name>
  10. <version>1.0</version>
  11. <signature>struct</signature>
  12. <help>
  13. Read the system's "/proc/cpuinfo" special file and return the information in
  14. the form of a STRUCT with the members based on the lines returned from the
  15. "file". All values are either INT or STRING, based on the disposition of the
  16. data itself. The exception to this is the key "flags", which is an ARRAY of
  17. STRING.
  18. </help>
  19. <code language="perl">
  20. <![CDATA[
  21. #!/usr/bin/perl
  22. ###############################################################################
  23. #
  24. #   Sub Name:       linux_proc_cpuinfo
  25. #
  26. #   Description:    Read the /proc/cpuinfo on a Linux server and return a
  27. #                   STRUCT with the information.
  28. #
  29. #   Arguments:      None.
  30. #
  31. #   Returns:        hashref
  32. #
  33. ###############################################################################
  34. sub linux_proc_sysinfo
  35. {
  36.     use strict;
  37.  
  38.     my (%cpuinfo, $line, $key, $value);
  39.     local *F;
  40.  
  41.     open(F, '/proc/cpuinfo') or
  42.         return RPC::XML::fault->new(501, "Cannot open /proc/cpuinfo: $!");
  43.  
  44.     while (defined($line = <F>))
  45.     {
  46.         chomp $line;
  47.         next if ($line =~ /^\s*$/);
  48.  
  49.         ($key, $value) = split(/\s+:\s+/, $line, 2);
  50.         $key =~ s/ /_/g;
  51.         $cpuinfo{$key} = ($key eq 'flags') ? [ split(/ /, $value) ] : $value;
  52.     }
  53.     close(F);
  54.  
  55.     \%cpuinfo;
  56. }
  57.  
  58. __END__
  59. ]]></code>
  60. </proceduredef>
  61.